#ifndef MATERIALDATALISTMODEL_H
#define MATERIALDATALISTMODEL_H

#include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include <materialmanager.h>

struct MaterialDataDelegator
{
  virtual int GetNumberOfMaterialDatas() const = 0;
  virtual MaterialData* GetMaterialData (int idx) = 0 ;
};

class MaterialDataListModel : public QAbstractItemModel
{
  Q_OBJECT
private:
  MaterialDataDelegator*  _delegator;

public:
  MaterialDataListModel ();

  void SetDelegator (MaterialDataDelegator* delegator);
  MaterialData* GetMaterialData (int row);

  void Changed ();

  virtual int columnCount (const QModelIndex& parent = QModelIndex()) const;

  virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;

  virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const;

  virtual QModelIndex parent (const QModelIndex& index) const;

  virtual int rowCount (const QModelIndex& parent = QModelIndex()) const;

};

class AllShaderDelegator : public MaterialDataDelegator
{
private:
  MaterialManager*  _manager;
public:
  AllShaderDelegator (MaterialManager* manager = 0);

  void SetMaterialManager (MaterialManager* manager);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};

class AllProgramShaderDelegator : public MaterialDataDelegator
{
private:
  Program::ShaderProgram*  _program;
public:
  AllProgramShaderDelegator (Program::ShaderProgram* program = 0);

  void SetProgram (Program::ShaderProgram* program);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};


class AllProgramDelegator : public MaterialDataDelegator
{
private:
  MaterialManager*  _manager;
public:
  AllProgramDelegator (MaterialManager* manager = 0);

  void SetMaterialManager (MaterialManager* manager);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};

class AllEffectDelegator : public MaterialDataDelegator
{
private:
  MaterialManager*  _manager;
public:
  AllEffectDelegator (MaterialManager* manager = 0);

  void SetMaterialManager (MaterialManager* manager);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};


class AllTextureDelegator : public MaterialDataDelegator
{
private:
  MaterialManager*  _manager;
public:
  AllTextureDelegator (MaterialManager* manager = 0);

  void SetMaterialManager (MaterialManager* manager);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};


class AllMaterialDelegator : public MaterialDataDelegator
{
private:
  MaterialManager*  _manager;
public:
  AllMaterialDelegator (MaterialManager* manager = 0);

  void SetMaterialManager (MaterialManager* manager);

  virtual int GetNumberOfMaterialDatas () const;
  virtual MaterialData* GetMaterialData (int idx);
};

class MaterialDataSortFilterProxModel : public QSortFilterProxyModel
{
  Q_OBJECT
private:
  QString	_filter;

  MaterialDataListModel*  _model;

protected:
  virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const ;

public:
  MaterialDataSortFilterProxModel (MaterialDataListModel* model, QObject* parent = 0);

  void ModelChanged ();
  void SetFilter (const QString& filter);
  const QString& GetFilter () const;
};


#endif // MATERIALDATALISTMODEL_H
